package com.service.impl;

import com.mapper.OrderProjectMapper;
import com.mapper.UserMapper;
import com.pojo.OrderProject;
import com.pojo.Project;
import com.pojo.Returner;
import com.pojo.User;
import com.service.OrderProjectService;
import com.service.ProjectService;
import com.service.ReturnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderProjectServiceImpl implements OrderProjectService {
    @Autowired
    private ReturnerService returnerService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private OrderProjectMapper orderProjectMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public OrderProject selectByRetrunId(long id) {
        /**
         * 第一步，根据回报id来查询回报内容对象
         * 第二步根据查询出来的对象来进行项目的基本信息查询
         * 将查询出来的信息展示到回报项信息和购买数量
         * 包括项目名称、项目发起人、回报内容、回报数量、支持单价、配送费用
         */
        Returner returner = returnerService.selectByreturnid(id);
        Project project = projectService.selectProjectById(returner.getProjectid());
        User user = userMapper.selectById(project.getUserid());
        OrderProject orderProject = new OrderProject(0,project.getProjectName(),
                user.getName(),
                returner.getContent(),
                returner.getCount(),
                returner.getSupportmoney(),
                returner.getFreight(),
                0
                );
        return orderProject;
    }

    @Override
    public int insertOrderProject(OrderProject orderProject) {
        return orderProjectMapper.insertOrderProject(orderProject);
    }

    @Override
    public OrderProject selectOrderProject(long orderId) {
        OrderProject orderProject = orderProjectMapper.selectByOrderId(orderId);
       /* Project project = projectService.selectProjectById(orderProject.getId());
        orderProject.setProject(project);*/
        return orderProject;
    }

    @Override
    public int deleteOrderProject(long orderId) {
        int i = orderProjectMapper.deleteOrderProject(orderId);
        return i;
    }

    @Override
    public String selectProjectNameByOrderId(long orderId) {
        return orderProjectMapper.selectProjectNameByOrderId(orderId);
    }
}
